package com.ren.mvpdemo.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.ren.mvpdemo.R;
import com.ren.mvpdemo.bean.Bean;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by asus on 2018/5/16.
 */

public class MyAdapter extends RecyclerView.Adapter<MyAdapter.MyViewHolder> {
    private Context mContext;

    private List<Bean.DataBean> list = new ArrayList<>();

    public MyAdapter(Context context,List<Bean.DataBean> list){
        this.mContext = context;
        this.list = list;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_layout,parent,false);
        MyViewHolder myViewHolder = new MyViewHolder(view);
        return myViewHolder;
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        holder.tv_item.setText(list.get(position).getAddress());
    }

    @Override
    public int getItemCount() {
        return null == list ? 0 : list.size() ;
    }

    public static class MyViewHolder extends RecyclerView.ViewHolder{
        private TextView tv_item;
        public MyViewHolder(View itemView) {
            super(itemView);
            tv_item = itemView.findViewById(R.id.tv_item);
        }
    }
}
